using System;
using System.Data;
using System.Globalization;
using System.Text;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

namespace OracleInternal.ServiceObjects
{
	internal class OracleGlobalizationImpl : ICloneable, IDisposable
	{
		private const string DEFAULT_LANGUAGE_TERRITORY = "AMERICAN_AMERICA";

		private const string DEFAULT_LANGUAGE = "AMERICAN";

		internal string m_calendar;

		internal string m_comparison;

		internal string m_currency;

		internal string m_dateFormat;

		internal string m_dateLanguage;

		internal string m_dualCurrency;

		internal string m_isoCurrency;

		internal string m_language;

		internal string m_lengthSemantics;

		internal bool m_nCharConvException;

		internal string m_numericCharacters;

		internal string m_sort;

		internal string m_territory;

		internal string m_timeStampFormat;

		internal string m_timeStampTZFormat;

		internal string m_timeZone;

		private string m_error_msg;

		private int m_error_code;

		private OracleCommand m_cmd;

		internal OracleGlobalizationImpl()
		{
		}

		internal OracleGlobalizationImpl(int lcid)
		{
			int zoneID = 0;
			GetLocaleSpecificNLSValues(lcid, ref m_language, ref m_territory, ref m_timeZone, ref zoneID);
		}

		internal static string GetNLSLANG(int lcid)
		{
			string text = "AMERICAN_AMERICA";
			return lcid switch
			{
				1078 => "AMERICAN_SOUTH AFRICA", 
				1052 => "AMERICAN_AMERICA", 
				1025 => "ARABIC_SAUDI ARABIA", 
				2049 => "ARABIC_IRAQ", 
				3073 => "ARABIC_EGYPT", 
				4097 => "ARABIC_LIBYA", 
				5121 => "ARABIC_ALGERIA", 
				6145 => "ARABIC_MOROCCO", 
				7169 => "ARABIC_TUNISIA", 
				8193 => "ARABIC_OMAN", 
				9217 => "ARABIC_YEMEN", 
				10241 => "ARABIC_SYRIA", 
				11265 => "ARABIC_JORDAN", 
				12289 => "ARABIC_LEBANON", 
				13313 => "ARABIC_KUWAIT", 
				14337 => "ARABIC_UNITED ARAB EMIRATES", 
				15361 => "ARABIC_BAHRAIN", 
				16385 => "ARABIC_QATAR", 
				1067 => "AMERICAN_AMERICA", 
				1068 => "AZERBAIJANI_AZERBAIJAN", 
				2092 => "AZERBAIJANI_AZERBAIJAN", 
				1069 => "AMERICAN_AMERICA", 
				1059 => "AMERICAN_AMERICA", 
				1093 => "BANGLA_INDIA", 
				5146 => "AMERICAN_AMERICA", 
				1026 => "BULGARIAN_BULGARIA", 
				1027 => "CATALAN_CATALONIA", 
				1028 => "TRADITIONAL CHINESE_TAIWAN", 
				2052 => "SIMPLIFIED CHINESE_CHINA", 
				3076 => "TRADITIONAL CHINESE_HONG KONG", 
				4100 => "SIMPLIFIED CHINESE_SINGAPORE", 
				5124 => "SIMPLIFIED CHINESE_CHINA", 
				1050 => "CROATIAN_CROATIA", 
				4122 => "CROATIAN_CROATIA", 
				1029 => "CZECH_CZECH REPUBLIC", 
				1030 => "DANISH_DENMARK", 
				1125 => "AMERICAN_AMERICA", 
				1043 => "DUTCH_THE NETHERLANDS", 
				2067 => "DUTCH_BELGIUM", 
				1033 => "AMERICAN_AMERICA", 
				2057 => "ENGLISH_UNITED KINGDOM", 
				3081 => "ENGLISH_AUSTRALIA", 
				4105 => "ENGLISH_CANADA", 
				5129 => "ENGLISH_NEW ZEALAND", 
				6153 => "ENGLISH_IRELAND", 
				7177 => "ENGLISH_SOUTH AFRICA", 
				8201 => "ENGLISH_UNITED KINGDOM", 
				9225 => "ENGLISH_UNITED KINGDOM", 
				10249 => "ENGLISH_UNITED KINGDOM", 
				11273 => "ENGLISH_UNITED KINGDOM", 
				12297 => "ENGLISH_UNITED KINGDOM", 
				13321 => "ENGLISH_PHILIPPINES", 
				1061 => "ESTONIAN_ESTONIA", 
				1080 => "AMERICAN_AMERICA", 
				1065 => "AMERICAN_AMERICA", 
				1035 => "FINNISH_FINLAND", 
				1036 => "FRENCH_FRANCE", 
				2060 => "FRENCH_BELGIUM", 
				3084 => "CANADIAN FRENCH_CANADA", 
				4108 => "FRENCH_SWITZERLAND", 
				5132 => "FRENCH_LUXEMBOURG", 
				6156 => "FRENCH_FRANCE", 
				1079 => "AMERICAN_AMERICA", 
				1110 => "AMERICAN_SPAIN", 
				1031 => "GERMAN_GERMANY", 
				2055 => "GERMAN_SWITZERLAND", 
				3079 => "GERMAN_AUSTRIA", 
				4103 => "GERMAN_LUXEMBOURG", 
				5127 => "GERMAN_GERMANY", 
				1032 => "GREEK_GREECE", 
				1095 => "GUJARATI_INDIA", 
				1037 => "HEBREW_ISRAEL", 
				1081 => "HINDI_INDIA", 
				1038 => "HUNGARIAN_HUNGARY", 
				1039 => "ICELANDIC_ICELAND", 
				1057 => "INDONESIAN_INDONESIA", 
				1040 => "ITALIAN_ITALY", 
				2064 => "ITALIAN_SWITZERLAND", 
				1041 => "JAPANESE_JAPAN", 
				1099 => "KANNADA_INDIA", 
				1087 => "CYRILLIC KAZAKH_KAZAKHSTAN", 
				1111 => "AMERICAN_AMERICA", 
				1042 => "KOREAN_KOREA", 
				1088 => "AMERICAN_AMERICA", 
				1062 => "LATVIAN_LATVIA", 
				1063 => "LITHUANIAN_LITHUANIA", 
				1071 => "MACEDONIAN_FYR MACEDONIA", 
				1086 => "MALAY_MALAYSIA", 
				2110 => "MALAY_MALAYSIA", 
				1100 => "MALAYALAM_INDIA", 
				1082 => "AMERICAN_AMERICA", 
				1153 => "AMERICAN_NEW ZEALAND", 
				1102 => "MARATHI_INDIA", 
				1104 => "AMERICAN_AMERICA", 
				1132 => "AMERICAN_AMERICA", 
				1044 => "NORWEGIAN_NORWAY", 
				2068 => "NORWEGIAN_NORWAY", 
				1045 => "POLISH_POLAND", 
				1046 => "BRAZILIAN PORTUGUESE_BRAZIL", 
				2070 => "PORTUGUESE_PORTUGAL", 
				1094 => "PUNJABI_INDIA", 
				1131 => "AMERICAN_AMERICA", 
				2155 => "AMERICAN_ECUADOR", 
				3179 => "AMERICAN_PERU", 
				1048 => "ROMANIAN_ROMANIA", 
				1049 => "RUSSIAN_RUSSIA", 
				9275 => "AMERICAN_FINLAND", 
				4155 => "AMERICAN_NORWAY", 
				5179 => "AMERICAN_SWEDEN", 
				3131 => "AMERICAN_FINLAND", 
				1083 => "AMERICAN_NORWAY", 
				2107 => "AMERICAN_SWEDEN", 
				8251 => "AMERICAN_FINLAND", 
				6203 => "AMERICAN_NORWAY", 
				7227 => "AMERICAN_SWEDEN", 
				1103 => "AMERICAN_AMERICA", 
				2074 => "LATIN SERBIAN_SERBIA AND MONTENEGRO", 
				6170 => "LATIN SERBIAN_SERBIA AND MONTENEGRO", 
				3098 => "CYRILLIC SERBIAN_SERBIA AND MONTENEGRO", 
				7194 => "CYRILLIC SERBIAN_SERBIA AND MONTENEGRO", 
				1051 => "SLOVAK_SLOVAKIA", 
				1060 => "SLOVENIAN_SLOVENIA", 
				1034 => "SPANISH_SPAIN", 
				2058 => "MEXICAN SPANISH_MEXICO", 
				3082 => "SPANISH_SPAIN", 
				4106 => "LATIN AMERICAN SPANISH_GUATEMALA", 
				5130 => "LATIN AMERICAN SPANISH_COSTA RICA", 
				6154 => "LATIN AMERICAN SPANISH_PANAMA", 
				7178 => "LATIN AMERICAN SPANISH_AMERICA", 
				8202 => "LATIN AMERICAN SPANISH_VENEZUELA", 
				9226 => "LATIN AMERICAN SPANISH_COLOMBIA", 
				10250 => "LATIN AMERICAN SPANISH_PERU", 
				11274 => "LATIN AMERICAN SPANISH_ARGENTINA", 
				12298 => "LATIN AMERICAN SPANISH_ECUADOR", 
				13322 => "LATIN AMERICAN SPANISH_CHILE", 
				14346 => "LATIN AMERICAN SPANISH_AMERICA", 
				15370 => "LATIN AMERICAN SPANISH_AMERICA", 
				16394 => "LATIN AMERICAN SPANISH_AMERICA", 
				17418 => "LATIN AMERICAN SPANISH_EL SALVADOR", 
				18442 => "LATIN AMERICAN SPANISH_AMERICA", 
				19466 => "LATIN AMERICAN SPANISH_NICARAGUA", 
				20490 => "LATIN AMERICAN SPANISH_PUERTO RICO", 
				1089 => "AMERICAN_AMERICA", 
				1053 => "SWEDISH_SWEDEN", 
				2077 => "SWEDISH_FINLAND", 
				1114 => "AMERICAN_SYRIA", 
				1097 => "TAMIL_INDIA", 
				1092 => "AMERICAN_AMERICA", 
				1098 => "TELUGU_INDIA", 
				1054 => "THAI_THAILAND", 
				1074 => "AMERICAN_SOUTH AFRICA", 
				1055 => "TURKISH_TURKEY", 
				1058 => "UKRAINIAN_UKRAINE", 
				1056 => "AMERICAN_AMERICA", 
				1091 => "LATIN UZBEK_UZBEKISTAN", 
				2115 => "CYRILLIC UZBEK_UZBEKISTAN", 
				1066 => "VIETNAMESE_VIETNAM", 
				1106 => "AMERICAN_UNITED KINGDOM", 
				1076 => "AMERICAN_SOUTH AFRICA", 
				1077 => "AMERICAN_SOUTH AFRICA", 
				_ => "AMERICAN_AMERICA", 
			};
		}

		internal static void GetLocaleSpecificNLSValues(int lcid, ref string language, ref string territory, ref string timezone, ref int zoneID)
		{
			string[] array = GetNLSLANG(lcid).Split('_');
			language = array[0];
			territory = array[1];
			TimeZoneInfo local = TimeZoneInfo.Local;
			if (ZoneIdMap.isValidRegion(local.Id))
			{
				zoneID = ZoneIdMap.GetRegionID(local.Id);
			}
			else
			{
				zoneID = TimeStamp.GetZoneId(local.Id);
			}
			if (TimeStamp.IsValidZoneId(zoneID))
			{
				timezone = TimeStamp.GetZoneName(zoneID);
				return;
			}
			DateTime now = DateTime.Now;
			string arg = Math.Abs(local.GetUtcOffset(now).Hours).ToString("00", CultureInfo.InvariantCulture);
			string arg2 = Math.Abs(local.GetUtcOffset(now).Minutes).ToString("00", CultureInfo.InvariantCulture);
			string arg3 = ((local.BaseUtcOffset >= TimeSpan.Zero) ? "+" : "-");
			timezone = $"{arg3}{arg}:{arg2}";
		}

		internal static string CreateAlterSessionBlockForOAUTH(int lcid, ref int zoneID)
		{
			string language = string.Empty;
			string territory = string.Empty;
			string timezone = string.Empty;
			GetLocaleSpecificNLSValues(lcid, ref language, ref territory, ref timezone, ref zoneID);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("ALTER SESSION SET ");
			stringBuilder.AppendFormat(" NLS_LANGUAGE='{0}' ", language);
			stringBuilder.AppendFormat(" NLS_TERRITORY='{0}' ", territory);
			stringBuilder.AppendFormat(" TIME_ZONE='{0}' ", timezone);
			return stringBuilder.ToString();
		}

		internal void RefreshFrom(OracleGlobalizationImpl oraGlob)
		{
			m_calendar = oraGlob.m_calendar;
			m_comparison = oraGlob.m_comparison;
			m_currency = oraGlob.m_currency;
			m_dateFormat = oraGlob.m_dateFormat;
			m_dateLanguage = oraGlob.m_dateLanguage;
			m_dualCurrency = oraGlob.m_dualCurrency;
			m_isoCurrency = oraGlob.m_isoCurrency;
			m_language = oraGlob.m_language;
			m_lengthSemantics = oraGlob.m_lengthSemantics;
			m_nCharConvException = oraGlob.m_nCharConvException;
			m_numericCharacters = oraGlob.m_numericCharacters;
			m_sort = oraGlob.m_sort;
			m_territory = oraGlob.m_territory;
			m_timeStampFormat = oraGlob.m_timeStampFormat;
			m_timeStampTZFormat = oraGlob.m_timeStampTZFormat;
			m_timeZone = oraGlob.m_timeZone;
		}

		internal void AlterSession(OracleGlobalizationImpl oraGlob, OracleConnection con)
		{
			if (oraGlob == null || (this != oraGlob && oraGlob.Equals(this)))
			{
				return;
			}
			if (m_cmd == null)
			{
				m_cmd = new OracleCommand
				{
					CommandType = CommandType.Text
				};
			}
			m_cmd.Connection = con;
			m_cmd.Parameters.Clear();
			bool flag = false;
			bool flag2 = false;
			StringBuilder stringBuilder = new StringBuilder("DECLARE ");
			stringBuilder.AppendFormat(" err_code VARCHAR2(2000); ");
			stringBuilder.AppendFormat(" err_msg VARCHAR2(2000); ");
			stringBuilder.AppendFormat(" BEGIN ");
			if (this == oraGlob)
			{
				CreateDerivedSelectBlock(oraGlob, stringBuilder, onConnect: true, nls_lang: true, nls_territory: true);
				stringBuilder.AppendFormat(" SELECT '0' into :p_err_code from dual; ");
				stringBuilder.AppendFormat(" SELECT '0' into :p_err_msg from dual; ");
			}
			else
			{
				StringBuilder stringBuilder2 = new StringBuilder("");
				CreateSingleAlterSessionBlock(stringBuilder2, oraGlob);
				if (stringBuilder2.Length == 0)
				{
					return;
				}
				stringBuilder.AppendFormat(" EXECUTE IMMEDIATE 'ALTER SESSION SET {0} ';", stringBuilder2);
				flag = string.Compare(oraGlob.m_language, m_language, ignoreCase: true) != 0;
				flag2 = string.Compare(oraGlob.m_territory, m_territory) != 0;
				CreateDerivedSelectBlock(oraGlob, stringBuilder, onConnect: false, flag, flag2);
				stringBuilder.AppendFormat(" SELECT '0' into :p_err_code from dual; ");
				stringBuilder.AppendFormat(" SELECT '0' into :p_err_msg from dual; ");
				stringBuilder.AppendFormat(" EXCEPTION WHEN OTHERS THEN ");
				stringBuilder.AppendFormat(" err_code := substr(SQLCODE, 1, 2000); ");
				stringBuilder.AppendFormat(" err_msg := substr(SQLERRM, 1, 2000); ");
				CreateDerivedSelectBlock(oraGlob, stringBuilder, onConnect: false, flag, flag2);
				stringBuilder.AppendFormat(" SELECT err_code into :p_err_code from dual; ");
				stringBuilder.AppendFormat(" SELECT err_msg into :p_err_msg from dual; ");
			}
			stringBuilder.AppendFormat(" END;");
			m_cmd.CommandText = stringBuilder.ToString();
			OracleParameter oracleParameter = null;
			OracleParameter oracleParameter2 = null;
			OracleParameter oracleParameter3 = null;
			OracleParameter oracleParameter4 = null;
			if (this == oraGlob || (oraGlob.m_calendar != null && string.Compare(oraGlob.m_calendar, m_calendar, ignoreCase: true) != 0))
			{
				oracleParameter = new OracleParameter("p_nls_calendar", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter);
			}
			if (this == oraGlob || (oraGlob.m_comparison != null && string.Compare(oraGlob.m_comparison, m_comparison, ignoreCase: true) != 0))
			{
				oracleParameter2 = new OracleParameter("p_nls_comp", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter2);
			}
			if (this == oraGlob || (oraGlob.m_lengthSemantics != null && string.Compare(oraGlob.m_lengthSemantics, m_lengthSemantics, ignoreCase: true) != 0))
			{
				oracleParameter3 = new OracleParameter("p_nls_length_semantics", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter3);
			}
			if (this == oraGlob || !oraGlob.m_nCharConvException == m_nCharConvException)
			{
				oracleParameter4 = new OracleParameter("p_nls_nchar_conv_excep", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter4);
			}
			OracleParameter oracleParameter5 = null;
			OracleParameter oracleParameter6 = null;
			if (flag || this == oraGlob || (oraGlob.m_dateLanguage != null && string.Compare(oraGlob.m_dateLanguage, m_dateLanguage, ignoreCase: true) != 0))
			{
				oracleParameter5 = new OracleParameter("p_nls_date_lang", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter5);
			}
			if (flag || this == oraGlob || (oraGlob.m_sort != null && string.Compare(oraGlob.m_sort, m_sort, ignoreCase: true) != 0))
			{
				oracleParameter6 = new OracleParameter("p_nls_sort", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter6);
			}
			OracleParameter oracleParameter7 = null;
			OracleParameter oracleParameter8 = null;
			OracleParameter oracleParameter9 = null;
			OracleParameter oracleParameter10 = null;
			OracleParameter oracleParameter11 = null;
			OracleParameter oracleParameter12 = null;
			OracleParameter oracleParameter13 = null;
			if (flag2 || this == oraGlob || (oraGlob.m_currency != null && string.Compare(oraGlob.m_currency, m_currency, ignoreCase: true) != 0))
			{
				oracleParameter7 = new OracleParameter("p_nls_currency", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter7);
			}
			if (flag2 || this == oraGlob || (oraGlob.m_dateFormat != null && string.Compare(oraGlob.m_dateFormat, m_dateFormat, ignoreCase: true) != 0))
			{
				oracleParameter8 = new OracleParameter("p_nls_date_format", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter8);
			}
			if (flag2 || this == oraGlob || (oraGlob.m_isoCurrency != null && string.Compare(oraGlob.m_isoCurrency, m_isoCurrency, ignoreCase: true) != 0))
			{
				oracleParameter9 = new OracleParameter("p_nls_iso_currency", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter9);
			}
			if (flag2 || this == oraGlob || (oraGlob.m_numericCharacters != null && string.Compare(oraGlob.m_numericCharacters, m_numericCharacters, ignoreCase: true) != 0))
			{
				oracleParameter10 = new OracleParameter("p_nls_numeric_chars", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter10);
			}
			if (flag2 || this == oraGlob || (oraGlob.m_dualCurrency != null && string.Compare(oraGlob.m_dualCurrency, m_dualCurrency, ignoreCase: true) != 0))
			{
				oracleParameter11 = new OracleParameter("p_nls_dual_currency", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter11);
			}
			if (flag2 || this == oraGlob || (oraGlob.m_timeStampFormat != null && string.Compare(oraGlob.m_timeStampFormat, m_timeStampFormat, ignoreCase: true) != 0))
			{
				oracleParameter12 = new OracleParameter("p_nls_timestamp", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter12);
			}
			if (flag2 || this == oraGlob || (oraGlob.m_timeStampTZFormat != null && string.Compare(oraGlob.m_timeStampTZFormat, m_timeStampTZFormat, ignoreCase: true) != 0))
			{
				oracleParameter13 = new OracleParameter("p_nls_timestamp_tz", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter13);
			}
			OracleParameter oracleParameter14 = new OracleParameter("p_err_code", OracleDbType.Varchar2, 2000, "", ParameterDirection.Output);
			m_cmd.Parameters.Add(oracleParameter14);
			OracleParameter oracleParameter15 = new OracleParameter("p_err_msg", OracleDbType.Varchar2, 2000, "", ParameterDirection.Output);
			m_cmd.Parameters.Add(oracleParameter15);
			m_cmd.ExecuteNonQuery();
			if (flag || this == oraGlob)
			{
				m_language = oraGlob.m_language;
			}
			if (flag2 || this == oraGlob)
			{
				m_territory = oraGlob.m_territory;
			}
			if (oraGlob.m_timeZone != null && string.Compare(oraGlob.m_timeZone, m_timeZone, ignoreCase: true) != 0)
			{
				m_timeZone = oraGlob.m_timeZone;
			}
			if (this == oraGlob || (oraGlob.m_calendar != null && string.Compare(oraGlob.m_calendar, m_calendar, ignoreCase: true) != 0))
			{
				m_calendar = oracleParameter.Value.ToString();
			}
			if (this == oraGlob || (oraGlob.m_comparison != null && string.Compare(oraGlob.m_comparison, m_comparison, ignoreCase: true) != 0))
			{
				m_comparison = oracleParameter2.Value.ToString();
			}
			if (this == oraGlob || (oraGlob.m_lengthSemantics != null && string.Compare(oraGlob.m_lengthSemantics, m_lengthSemantics, ignoreCase: true) != 0))
			{
				m_lengthSemantics = oracleParameter3.Value.ToString();
			}
			if (this == oraGlob || !oraGlob.m_nCharConvException == m_nCharConvException)
			{
				m_nCharConvException = (oracleParameter4.Value.ToString()!.ToLowerInvariant().Equals("true") ? true : false);
			}
			if (flag || this == oraGlob || (oraGlob.m_dateLanguage != null && string.Compare(oraGlob.m_dateLanguage, m_dateLanguage, ignoreCase: true) != 0))
			{
				m_dateLanguage = oracleParameter5.Value.ToString();
			}
			if (flag || this == oraGlob || (oraGlob.m_sort != null && string.Compare(oraGlob.m_sort, m_sort, ignoreCase: true) != 0))
			{
				m_sort = oracleParameter6.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_currency != null && string.Compare(oraGlob.m_currency, m_currency, ignoreCase: true) != 0))
			{
				m_currency = oracleParameter7.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_dateFormat != null && string.Compare(oraGlob.m_dateFormat, m_dateFormat, ignoreCase: true) != 0))
			{
				m_dateFormat = oracleParameter8.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_isoCurrency != null && string.Compare(oraGlob.m_isoCurrency, m_isoCurrency, ignoreCase: true) != 0))
			{
				m_isoCurrency = oracleParameter9.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_numericCharacters != null && string.Compare(oraGlob.m_numericCharacters, m_numericCharacters, ignoreCase: true) != 0))
			{
				m_numericCharacters = oracleParameter10.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_dualCurrency != null && string.Compare(oraGlob.m_dualCurrency, m_dualCurrency, ignoreCase: true) != 0))
			{
				m_dualCurrency = oracleParameter11.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_timeStampFormat != null && string.Compare(oraGlob.m_timeStampFormat, m_timeStampFormat, ignoreCase: true) != 0))
			{
				m_timeStampFormat = oracleParameter12.Value.ToString();
			}
			if (flag2 || this == oraGlob || (oraGlob.m_timeStampTZFormat != null && string.Compare(oraGlob.m_timeStampTZFormat, m_timeStampTZFormat, ignoreCase: true) != 0))
			{
				m_timeStampTZFormat = oracleParameter13.Value.ToString();
			}
			string value = oracleParameter14.Value.ToString();
			m_error_code = Convert.ToInt32(value);
			m_error_msg = oracleParameter15.Value.ToString();
			try
			{
				if (m_error_msg != null && !m_error_msg.ToLowerInvariant().Equals("0"))
				{
					if (flag || this == oraGlob)
					{
						m_language = oraGlob.m_language;
						m_dateLanguage = oracleParameter5.Value.ToString();
						m_sort = oracleParameter6.Value.ToString();
					}
					if (flag2 || this == oraGlob)
					{
						m_territory = oraGlob.m_territory;
						m_currency = oracleParameter7.Value.ToString();
						m_dateFormat = oracleParameter8.Value.ToString();
						m_isoCurrency = oracleParameter9.Value.ToString();
						m_numericCharacters = oracleParameter10.Value.ToString();
						m_dualCurrency = oracleParameter11.Value.ToString();
						m_timeStampFormat = oracleParameter12.Value.ToString();
						m_timeStampTZFormat = oracleParameter13.Value.ToString();
					}
					m_cmd.Connection = null;
					throw new OracleException(m_error_code, string.Empty, string.Empty, m_error_msg);
				}
			}
			finally
			{
				foreach (OracleParameter parameter in m_cmd.Parameters)
				{
					parameter.Dispose();
				}
			}
			m_cmd.Connection = null;
		}

		internal void SelectNLSValues(OracleConnection con)
		{
			try
			{
				if (m_cmd == null)
				{
					m_cmd = new OracleCommand
					{
						CommandType = CommandType.Text
					};
				}
				m_cmd.Connection = con;
				m_cmd.Parameters.Clear();
				StringBuilder stringBuilder = new StringBuilder("DECLARE ");
				stringBuilder.AppendFormat(" err_code VARCHAR2(2000); ");
				stringBuilder.AppendFormat(" err_msg VARCHAR2(2000); ");
				stringBuilder.AppendFormat(" BEGIN ");
				stringBuilder.AppendFormat(" SELECT VALUE into :p_nls_comp from nls_session_parameters where PARAMETER='NLS_COMP';");
				stringBuilder.AppendFormat(" SELECT VALUE into :p_nls_length_semantics from nls_session_parameters where PARAMETER='NLS_LENGTH_SEMANTICS';");
				stringBuilder.AppendFormat(" SELECT VALUE into :p_nls_nchar_conv_excep from nls_session_parameters where PARAMETER='NLS_NCHAR_CONV_EXCP';");
				stringBuilder.AppendFormat(" SELECT '0' into :p_err_code from dual; ");
				stringBuilder.AppendFormat(" SELECT '0' into :p_err_msg from dual; ");
				stringBuilder.AppendFormat(" END;");
				m_cmd.CommandText = stringBuilder.ToString();
				OracleParameter oracleParameter = null;
				OracleParameter oracleParameter2 = null;
				OracleParameter oracleParameter3 = null;
				oracleParameter = new OracleParameter("p_nls_comp", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter);
				oracleParameter2 = new OracleParameter("p_nls_length_semantics", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter2);
				oracleParameter3 = new OracleParameter("p_nls_nchar_conv_excep", OracleDbType.Varchar2, 40, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter3);
				OracleParameter oracleParameter4 = new OracleParameter("p_err_code", OracleDbType.Varchar2, 2000, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter4);
				OracleParameter oracleParameter5 = new OracleParameter("p_err_msg", OracleDbType.Varchar2, 2000, "", ParameterDirection.Output);
				m_cmd.Parameters.Add(oracleParameter5);
				m_cmd.ExecuteNonQuery();
				m_comparison = oracleParameter.Value.ToString();
				m_lengthSemantics = oracleParameter2.Value.ToString();
				m_nCharConvException = (oracleParameter3.Value.ToString()!.ToLowerInvariant().Equals("true") ? true : false);
				string value = oracleParameter4.Value.ToString();
				m_error_code = Convert.ToInt32(value);
				m_error_msg = oracleParameter5.Value.ToString();
				if (m_error_msg != null && !m_error_msg.ToLowerInvariant().Equals("0"))
				{
					m_cmd.Connection = null;
				}
			}
			catch (Exception)
			{
			}
			finally
			{
				foreach (OracleParameter parameter in m_cmd.Parameters)
				{
					parameter.Dispose();
				}
			}
			m_cmd.Connection = null;
		}

		internal void CreateSingleAlterSessionBlock(StringBuilder sqlCmd, OracleGlobalizationImpl oraGlob)
		{
			if (oraGlob.m_language != null && string.Compare(oraGlob.m_language, m_language, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat("  NLS_LANGUAGE=\"{0}\" ", oraGlob.m_language);
			}
			if (oraGlob.m_territory != null && string.Compare(oraGlob.m_territory, m_territory, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_TERRITORY=\"{0}\" ", oraGlob.m_territory);
			}
			if (oraGlob.m_calendar != null && string.Compare(oraGlob.m_calendar, m_calendar, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_CALENDAR=\"{0}\" ", oraGlob.m_calendar);
			}
			if (oraGlob.m_dateLanguage != null && string.Compare(oraGlob.m_dateLanguage, m_dateLanguage, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_DATE_LANGUAGE=\"{0}\" ", oraGlob.m_dateLanguage);
			}
			if (oraGlob.m_currency != null && string.Compare(oraGlob.m_currency, m_currency, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_CURRENCY=\"{0}\" ", oraGlob.m_currency);
			}
			if (oraGlob.m_dateFormat != null && string.Compare(oraGlob.m_dateFormat, m_dateFormat, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_DATE_FORMAT=''{0}'' ", oraGlob.m_dateFormat);
			}
			if (oraGlob.m_isoCurrency != null && string.Compare(oraGlob.m_isoCurrency, m_isoCurrency, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_ISO_CURRENCY=\"{0}\" ", oraGlob.m_isoCurrency);
			}
			if (oraGlob.m_numericCharacters != null && string.Compare(oraGlob.m_numericCharacters, m_numericCharacters, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_NUMERIC_CHARACTERS=\"{0}\" ", oraGlob.m_numericCharacters);
			}
			if (oraGlob.m_sort != null && string.Compare(oraGlob.m_sort, m_sort, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_SORT=\"{0}\" ", oraGlob.m_sort);
			}
			if (oraGlob.m_comparison != null && string.Compare(oraGlob.m_comparison, m_comparison, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_COMP=\"{0}\" ", oraGlob.m_comparison);
			}
			if (oraGlob.m_dualCurrency != null && string.Compare(oraGlob.m_dualCurrency, m_dualCurrency, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_DUAL_CURRENCY=\"{0}\" ", oraGlob.m_dualCurrency);
			}
			if (oraGlob.m_lengthSemantics != null && string.Compare(oraGlob.m_lengthSemantics, m_lengthSemantics, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_LENGTH_SEMANTICS=\"{0}\" ", oraGlob.m_lengthSemantics);
			}
			if (!oraGlob.m_nCharConvException == m_nCharConvException)
			{
				sqlCmd.AppendFormat(" NLS_NCHAR_CONV_EXCP=\"{0}\" ", oraGlob.m_nCharConvException);
			}
			if (oraGlob.m_timeStampFormat != null && string.Compare(oraGlob.m_timeStampFormat, m_timeStampFormat, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_TIMESTAMP_FORMAT=''{0}'' ", oraGlob.m_timeStampFormat);
			}
			if (oraGlob.m_timeStampTZFormat != null && string.Compare(oraGlob.m_timeStampTZFormat, m_timeStampTZFormat, ignoreCase: true) != 0)
			{
				sqlCmd.AppendFormat(" NLS_TIMESTAMP_TZ_FORMAT=''{0}'' ", oraGlob.m_timeStampTZFormat);
			}
			if (oraGlob.m_timeZone != null && string.Compare(oraGlob.m_timeZone, m_timeZone, ignoreCase: true) != 0)
			{
				if (oraGlob.m_timeZone.ToLowerInvariant() == "local")
				{
					sqlCmd.AppendFormat(" TIME_ZONE=local ");
				}
				else if (oraGlob.m_timeZone.ToLowerInvariant() == "dbtimezone")
				{
					sqlCmd.AppendFormat(" TIME_ZONE=dbtimezone ");
				}
				else if (oraGlob.m_timeZone.Length > 0)
				{
					sqlCmd.AppendFormat(" TIME_ZONE=''{0}'' ", oraGlob.m_timeZone);
				}
			}
		}

		internal void CreateDerivedSelectBlock(OracleGlobalizationImpl oraGlob, StringBuilder sqlCmd, bool onConnect, bool nls_lang, bool nls_territory)
		{
			if (onConnect || (oraGlob.m_calendar != null && string.Compare(oraGlob.m_calendar, m_calendar, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_calendar from nls_session_parameters where PARAMETER='NLS_CALENDAR';");
			}
			if (onConnect || (oraGlob.m_comparison != null && string.Compare(oraGlob.m_comparison, m_comparison, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_comp from nls_session_parameters where PARAMETER='NLS_COMP';");
			}
			if (onConnect || (oraGlob.m_lengthSemantics != null && string.Compare(oraGlob.m_lengthSemantics, m_lengthSemantics, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_length_semantics from nls_session_parameters where PARAMETER='NLS_LENGTH_SEMANTICS';");
			}
			if (onConnect || !oraGlob.m_nCharConvException == m_nCharConvException)
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_nchar_conv_excep from nls_session_parameters where PARAMETER='NLS_NCHAR_CONV_EXCP';");
			}
			if (nls_lang || (oraGlob.m_dateLanguage != null && string.Compare(oraGlob.m_dateLanguage, m_dateLanguage, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_date_lang from nls_session_parameters where PARAMETER='NLS_DATE_LANGUAGE';");
			}
			if (nls_lang || (oraGlob.m_sort != null && string.Compare(oraGlob.m_sort, m_sort, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_sort from nls_session_parameters where PARAMETER='NLS_SORT';");
			}
			if (nls_territory || (oraGlob.m_currency != null && string.Compare(oraGlob.m_currency, m_currency, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_currency from nls_session_parameters where PARAMETER='NLS_CURRENCY';");
			}
			if (nls_territory || (oraGlob.m_dateFormat != null && string.Compare(oraGlob.m_dateFormat, m_dateFormat, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_date_format from nls_session_parameters where PARAMETER='NLS_DATE_FORMAT';");
			}
			if (nls_territory || (oraGlob.m_isoCurrency != null && string.Compare(oraGlob.m_isoCurrency, m_isoCurrency, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_iso_currency from nls_session_parameters where PARAMETER='NLS_ISO_CURRENCY';");
			}
			if (nls_territory || (oraGlob.m_numericCharacters != null && string.Compare(oraGlob.m_numericCharacters, m_numericCharacters, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_numeric_chars from nls_session_parameters where PARAMETER='NLS_NUMERIC_CHARACTERS';");
			}
			if (nls_territory || (oraGlob.m_dualCurrency != null && string.Compare(oraGlob.m_dualCurrency, m_dualCurrency, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_dual_currency from nls_session_parameters where PARAMETER='NLS_DUAL_CURRENCY';");
			}
			if (nls_territory || (oraGlob.m_timeStampFormat != null && string.Compare(oraGlob.m_timeStampFormat, m_timeStampFormat, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_timestamp from nls_session_parameters where PARAMETER='NLS_TIMESTAMP_FORMAT';");
			}
			if (nls_territory || (oraGlob.m_timeStampTZFormat != null && string.Compare(oraGlob.m_timeStampTZFormat, m_timeStampTZFormat, ignoreCase: true) != 0))
			{
				sqlCmd.AppendFormat(" SELECT VALUE into :p_nls_timestamp_tz from nls_session_parameters where PARAMETER='NLS_TIMESTAMP_TZ_FORMAT';");
			}
		}

		public bool Equals(OracleGlobalizationImpl oraGlob)
		{
			if (oraGlob == null)
			{
				return false;
			}
			if (oraGlob.m_language != null && string.Compare(oraGlob.m_language, m_language, ignoreCase: true) == 0 && oraGlob.m_territory != null && string.Compare(oraGlob.m_territory, m_territory, ignoreCase: true) == 0 && oraGlob.m_calendar != null && string.Compare(oraGlob.m_calendar, m_calendar, ignoreCase: true) == 0 && oraGlob.m_comparison != null && string.Compare(oraGlob.m_comparison, m_comparison, ignoreCase: true) == 0 && oraGlob.m_currency != null && string.Compare(oraGlob.m_currency, m_currency, ignoreCase: true) == 0 && oraGlob.m_dualCurrency != null && string.Compare(oraGlob.m_dualCurrency, m_dualCurrency, ignoreCase: true) == 0 && oraGlob.m_isoCurrency != null && string.Compare(oraGlob.m_isoCurrency, m_isoCurrency, ignoreCase: true) == 0 && oraGlob.m_dateFormat != null && string.Compare(oraGlob.m_dateFormat, m_dateFormat, ignoreCase: true) == 0 && oraGlob.m_dateLanguage != null && string.Compare(oraGlob.m_dateLanguage, m_dateLanguage, ignoreCase: true) == 0 && oraGlob.m_lengthSemantics != null && string.Compare(oraGlob.m_lengthSemantics, m_lengthSemantics, ignoreCase: true) == 0 && oraGlob.m_nCharConvException == m_nCharConvException && oraGlob.m_numericCharacters != null && string.Compare(oraGlob.m_numericCharacters, m_numericCharacters, ignoreCase: true) == 0 && oraGlob.m_timeStampFormat != null && string.Compare(oraGlob.m_timeStampFormat, m_timeStampFormat, ignoreCase: true) == 0 && oraGlob.m_timeStampTZFormat != null && string.Compare(oraGlob.m_timeStampTZFormat, m_timeStampTZFormat, ignoreCase: true) == 0 && oraGlob.m_timeZone != null && string.Compare(oraGlob.m_timeZone, m_timeZone, ignoreCase: true) == 0)
			{
				if (oraGlob.m_sort != null)
				{
					return string.Compare(oraGlob.m_sort, m_sort, ignoreCase: true) == 0;
				}
				return false;
			}
			return false;
		}

		public object Clone()
		{
			return new OracleGlobalizationImpl
			{
				m_calendar = m_calendar,
				m_comparison = m_comparison,
				m_currency = m_currency,
				m_dateFormat = m_dateFormat,
				m_dateLanguage = m_dateLanguage,
				m_dualCurrency = m_dualCurrency,
				m_isoCurrency = m_isoCurrency,
				m_language = m_language,
				m_lengthSemantics = m_lengthSemantics,
				m_nCharConvException = m_nCharConvException,
				m_numericCharacters = m_numericCharacters,
				m_sort = m_sort,
				m_territory = m_territory,
				m_timeStampFormat = m_timeStampFormat,
				m_timeStampTZFormat = m_timeStampTZFormat,
				m_timeZone = m_timeZone
			};
		}

		public void Dispose()
		{
			if (m_cmd != null && !m_cmd.m_disposed)
			{
				m_cmd.Dispose();
			}
		}
	}
}
